import requests
from bs4 import BeautifulSoup

# 发送HTTP请求获取百度首页的HTML内容
url = 'https://news.baidu.com/'
response = requests.get(url)

# 确保请求成功
if response.status_code == 200:
    # 用BeautifulSoup解析HTML内容
    soup = BeautifulSoup(response.text, 'html.parser')

    # 使用BeautifulSoup的方法和属性来抓取所需的数据
    # 例如，抓取百度首页的标题
    title = soup.title.text
    print(title)
else:
    print('Failed to retrieve the webpage')